<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/14
 * Time: 13:08
 */

namespace app\index\controller;

use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use think\Validate;
use app\index\validate\Valid;

class Wdkcjc extends Common
{
    /**
     * 所有网点库存检查
     */
    public function allnetkucuncheck(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $xm = $this->request->param('xm');
        $fq = $this->request->param('fq');
        $hbwd = $this->request->param('hbwd');
        $jxs = $this->request->param('jxs');
        $sf = $this->request->param('sf');
        $hbcp = $this->request->param('hbcp');
        $xt = $this->request->param('xt');
        $cs = $this->request->param('cs');
        $this->assign([
            'xm'=>$xm,
            'fq'=>$fq,
            'hbwd'=>$hbwd,
            'jxs'=>$jxs,
            'sf'=>$sf,
            'hbcp'=>$hbcp,
            'xt'=>$xt,
            'cs'=>$cs,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        if($xm){
            $where['hbr_xm'] = ['like',"%{$xm}%"];
        }
        if($fq){
            $where['ssyxfq'] = ['like',"%{$fq}%"];
        }
        if($hbwd){
            $where['hbwd'] = ['like',"%{$hbwd}%"];
        }
        if($jxs){
            $where['ssjxs'] = ['like',"%{$jxs}%"];
        }
        if($sf){
            $where['ssyxsf'] = ['like',"%{$sf}%"];
        }
        if($hbcp){
            $where['cp_dpmc'] = ['like',"%{$hbcp}%"];
        }
        if($xt){
            $where['ssxt'] = ['like',"%{$xt}%"];
        }
        if($cs){
            $where['ssyxcs'] = ['like',"%{$cs}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_kcjc')->where($where)->count();
        $data = db('yd_kcjc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }
    /**
     * 所属网点库存检查
     */
    public function tonetkucuncheck(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $xm = $this->request->param('xm');
        $fq = $this->request->param('fq');
        $hbwd = $this->request->param('hbwd');
        $jxs = $this->request->param('jxs');
        $sf = $this->request->param('sf');
        $hbcp = $this->request->param('hbcp');
        $xt = $this->request->param('xt');
        $cs = $this->request->param('cs');
        $this->assign([
            'xm'=>$xm,
            'fq'=>$fq,
            'hbwd'=>$hbwd,
            'jxs'=>$jxs,
            'sf'=>$sf,
            'hbcp'=>$hbcp,
            'xt'=>$xt,
            'cs'=>$cs,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        $where['net_id'] = ['exp',"in(select id from cg_net where stuff like '%\"".session('employee_id')."\%')"];
        if($xm){
            $where['hbr_xm'] = ['like',"%{$xm}%"];
        }
        if($fq){
            $where['ssyxfq'] = ['like',"%{$fq}%"];
        }
        if($hbwd){
            $where['hbwd'] = ['like',"%{$hbwd}%"];
        }
        if($jxs){
            $where['ssjxs'] = ['like',"%{$jxs}%"];
        }
        if($sf){
            $where['ssyxsf'] = ['like',"%{$sf}%"];
        }
        if($hbcp){
            $where['cp_dpmc'] = ['like',"%{$hbcp}%"];
        }
        if($xt){
            $where['ssxt'] = ['like',"%{$xt}%"];
        }
        if($cs){
            $where['ssyxcs'] = ['like',"%{$cs}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_kcjc')->where($where)->count();
        $data = db('yd_kcjc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }
}